//
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
include "mainfile.php";
/********************************************/
/* Function to let your client login to see */
/* the stats */
/********************************************/
function clientlogin()
{
global $xoopsDB, $xoopsLogger, $xoopsConfig;
include("header.php");
echo "
";
include "footer.php";
}
/*********************************************/
/* Function to display the banners stats for */
/* each client */
/*********************************************/
function bannerstats($login, $pass)
{
global $xoopsDB, $xoopsConfig, $xoopsLogger;
if ($login == "" || $pass == "") {
redirect_header("banners.php",2);
exit();
}
$result = $xoopsDB->query(sprintf("SELECT cid, name, passwd FROM %s WHERE login=%s", $xoopsDB->prefix("bannerclient"), $xoopsDB->quoteString($login)));
list($cid, $name, $passwd) = $xoopsDB->fetchRow($result);
if ( $pass==$passwd ) {
include "header.php";
echo "
Current Active Banners for $name
ID
Imp. Made
Imp. Total
Imp. Left
Clicks
% Clicks
Functions ";
$result = $xoopsDB->query("select bid, imptotal, impmade, clicks, date from ".$xoopsDB->prefix("banner")." where cid=$cid");
while ( list($bid, $imptotal, $impmade, $clicks, $date) = $xoopsDB->fetchRow($result) ) {
if ( $impmade == 0 ) {
$percent = 0;
} else {
$percent = substr(100 * $clicks / $impmade, 0, 5);
}
if ( $imptotal == 0 ) {
$left = "Unlimited";
} else {
$left = $imptotal-$impmade;
}
$token =& XoopsMultiTokenHandler::quickCreate('banner_EmailStats');
echo "$bid
$impmade
$imptotal
$left
$clicks
$percent%
E-mail Stats ";
}
echo "
Following are your running Banners in ".htmlspecialchars($xoopsConfig['sitename'])."
";
$result = $xoopsDB->query("select bid, imageurl, clickurl, htmlbanner, htmlcode from ".$xoopsDB->prefix("banner")." where cid=$cid");
while ( list($bid, $imageurl, $clickurl,$htmlbanner, $htmlcode) = $xoopsDB->fetchRow($result) ) {
$numrows = $xoopsDB->getRowsNum($result);
if ($numrows>1) {
echo " ";
}
if (!empty($htmlbanner) && !empty($htmlcode)){
echo $myts->displayTarea($htmlcode);
}else{
if(strtolower(substr($imageurl,strrpos($imageurl,".")))==".swf") {
echo "";
echo " ";
echo " ";
echo "";
echo " ";
echo " ";
} else {
echo " ";
}
}
$token =& XoopsMultiTokenHandler::quickCreate('banner_EmailStats');
echo"Banner ID: $bid
Send E-Mail Stats for this Banner ";
if (!$htmlbanner){
$token =& XoopsMultiTokenHandler::quickCreate('banner_Change');
$clickurl = htmlspecialchars($clickurl, ENT_QUOTES);
echo "This Banner points to this URL
";
}
}
/* Finnished Banners */
echo " ";
if(!$result = $xoopsDB->query("select bid, impressions, clicks, datestart, dateend from ".$xoopsDB->prefix("bannerfinish")." where cid=$cid")){
echo "Banners Finished for $name
ID
Impressions
Clicks
% Clicks
Start Date
End Date ";
while ( list($bid, $impressions, $clicks, $datestart, $dateend) = $xoopsDB->fetchRow($result) ) {
$percent = substr(100 * $clicks / $impressions, 0, 5);
echo "$bid
$impressions
$clicks
$percent%
".formatTimestamp($datestart)."
".formatTimestamp($dateend)." ";
}
echo "
";
}
include "footer.php";
} else {
redirect_header("banners.php",2);
exit();
}
}
/*********************************************/
/* Function to let the client E-mail his */
/* banner Stats */
/*********************************************/
function EmailStats($login, $cid, $bid, $pass)
{
global $xoopsDB, $xoopsConfig;
if ($login != "" && $pass != "") {
$cid = intval($cid);
$bid = intval($bid);
if ($result2 = $xoopsDB->query(sprintf("select name, email, passwd from %s where cid=%u AND login=%s", $xoopsDB->prefix("bannerclient"), $cid, $xoopsDB->quoteString($login)))) {
list($name, $email, $passwd) = $xoopsDB->fetchRow($result2);
if ($pass == $passwd) {
if ($email == "") {
redirect_header("banners.php",3,"There isn't an email associated with client ".$name.". Please contact the Administrator");
exit();
} else {
if ($result = $xoopsDB->query("select bid, imptotal, impmade, clicks, imageurl, clickurl, date from ".$xoopsDB->prefix("banner")." where bid=$bid and cid=$cid")) {
list($bid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date) = $xoopsDB->fetchRow($result);
if ( $impmade == 0 ) {
$percent = 0;
} else {
$percent = substr(100 * $clicks / $impmade, 0, 5);
}
if ( $imptotal == 0 ) {
$left = "Unlimited";
$imptotal = "Unlimited";
} else {
$left = $imptotal-$impmade;
}
$fecha = date("F jS Y, h:iA.");
$subject = "Your Banner Statistics at ".$xoopsConfig['sitename'];
$message = "Following are the complete stats for your advertising investment at ". $xoopsConfig['sitename']." :\n\n\nClient Name: $name\nBanner ID: $bid\nBanner Image: $imageurl\nBanner URL: $clickurl\n\nImpressions Purchased: $imptotal\nImpressions Made: $impmade\nImpressions Left: $left\nClicks Received: $clicks\nClicks Percent: $percent%\n\n\nReport Generated on: $fecha";
$xoopsMailer =& getMailer();
$xoopsMailer->useMail();
$xoopsMailer->setToEmails($email);
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
$xoopsMailer->setFromName($xoopsConfig['sitename']);
$xoopsMailer->setSubject($subject);
$xoopsMailer->setBody($message);
$xoopsMailer->send();
$token =& XoopsMultiTokenHandler::quickCreate('banner_Ok');
redirect_header("banners.php?op=Ok&login=$login&pass=$pass&".$token->getUrl(), 3, "Statistics for your banner has been sent to your email address.");
exit();
}
}
}
}
}
redirect_header("banners.php",2);
exit();
}
/*********************************************/
/* Function to let the client to change the */
/* url for his banner */
/*********************************************/
function change_banner_url_by_client($login, $pass, $cid, $bid, $url)
{
global $xoopsDB;
if ($login != "" && $pass != "" && $url != "") {
$cid = intval($cid);
$bid = intval($bid);
$sql = sprintf("select passwd from %s where cid=%u and login=%s", $xoopsDB->prefix("bannerclient"), $cid, $xoopsDB->quoteString($login));
if ($result = $xoopsDB->query($sql)) {
list($passwd) = $xoopsDB->fetchRow($result);
if ( $pass == $passwd ) {
$sql = sprintf("update %s set clickurl=%s where bid=%u AND cid=%u", $xoopsDB->prefix("banner"), $xoopsDB->quoteString($url), $bid, $cid);
if ($xoopsDB->query($sql)) {
$token =& XoopsMultiTokenHandler::quickCreate('banner_Ok');
redirect_header("banners.php?op=Ok&login=$login&pass=$pass&".$token->getUrl(), 3, "URL has been changed.");
exit();
}
}
}
}
redirect_header("banners.php",2);
exit();
}
function clickbanner($bid)
{
global $xoopsDB;
if (is_int($bid) && $bid > 0) {
if (xoops_refcheck()) {
if ($bresult = $xoopsDB->query("select clickurl from ".$xoopsDB->prefix("banner")." where bid=$bid")) {
list($clickurl) = $xoopsDB->fetchRow($bresult);
$xoopsDB->queryF("update ".$xoopsDB->prefix("banner")." set clicks=clicks+1 where bid=$bid");
header ('Location: '.$clickurl);
}
}
}
exit();
}
$op = '';
if (!empty($_POST['op'])) {
$op = $_POST['op'];
} elseif (!empty($_GET['op'])) {
$op = $_GET['op'];
}
$myts =& MyTextSanitizer::getInstance();
switch ( $op ) {
case "click":
$bid = 0;
if (!empty($_GET['bid'])) {
$bid = intval($_GET['bid']);
}
clickbanner($bid);
break;
case "login":
clientlogin();
break;
case "Ok":
if (!XoopsMultiTokenHandler::quickValidate('banner_Ok')) {
redirect_header("banners.php");
exit();
}
$login = $pass = '';
if (!empty($_GET['login'])) {
$login = $myts->stripslashesGPC(trim($_GET['login']));
}
if (!empty($_GET['pass'])) {
$pass = $myts->stripslashesGPC(trim($_GET['pass']));
}
if (!empty($_POST['login'])) {
$login = $myts->stripslashesGPC(trim($_POST['login']));
}
if (!empty($_POST['pass'])) {
$pass = $myts->stripslashesGPC(trim($_POST['pass']));
}
bannerstats($login, $pass);
break;
case "Change":
if (!XoopsMultiTokenHandler::quickValidate('banner_Change')) {
redirect_header("banners.php");
exit();
}
$login = $pass = $url = '';
$bid = $cid = 0;
if (!empty($_POST['login'])) {
$login = $myts->stripslashesGPC(trim($_POST['login']));
}
if (!empty($_POST['pass'])) {
$pass = $myts->stripslashesGPC(trim($_POST['pass']));
}
if (!empty($_POST['url'])) {
$url = $myts->stripslashesGPC(trim($_POST['url']));
}
if (!empty($_POST['bid'])) {
$bid = intval($_POST['bid']);
}
if (!empty($_POST['cid'])) {
$cid = intval($_POST['cid']);
}
change_banner_url_by_client($login, $pass, $cid, $bid, $url);
break;
case "EmailStats":
if (!XoopsMultiTokenHandler::quickValidate('banner_EmailStats')) {
redirect_header("banners.php");
exit();
}
$login = $pass = '';
$bid = $cid = 0;
if (!empty($_GET['login'])) {
$login = $myts->stripslashesGPC(trim($_GET['login']));
}
if (!empty($_GET['pass'])) {
$pass = $myts->stripslashesGPC(trim($_GET['pass']));
}
if (!empty($_GET['bid'])) {
$bid = intval($_GET['bid']);
}
if (!empty($_GET['cid'])) {
$cid = intval($_GET['cid']);
}
EmailStats($login, $cid, $bid, $pass);
break;
default:
clientlogin();
break;
}
?>